package com.yanqu.road.server.cmd.activity.witchdraw;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.WitchDrawProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.witchDraw.WitchDrawModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_WITCH_DRAW_GET_USER_DATA, desc = "获取用户数据")
public class WitchDrawGetUserDataCmd extends AbstractCommand{

    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WitchDrawProto.WitchDrawGetUserDataReq witchDrawGetUserDataReq = WitchDrawProto.WitchDrawGetUserDataReq.parseFrom(packet.getBytes());
        activityId = witchDrawGetUserDataReq.getActivityId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(WitchDrawModule.class).getUserData(activityId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            WitchDrawProto.WitchDrawGetUserDataResp.Builder resp = WitchDrawProto.WitchDrawGetUserDataResp.newBuilder();
            resp.setRet(ret);
            player.sendPacket(ClientProtocol.U_WITCH_DRAW_GET_USER_DATA,resp);
        }
    }
}
